﻿#region usings
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Papa.Common;
using InsuranceAdjuster.Helpers;
using System.Windows.Navigation;
using InsuranceAdjuster.OccasionallyConnected;
using InsuranceAdjuster.OccasionallyConnected.Messages;

#endregion
namespace InsuranceAdjuster.ViewModels {
    
    public abstract class ViewModelBase : ViewModel, INavigable {
        private Object _Model = default(Object);
        private NavigationService _NavigationService;
        private NavigationContext _NavigationContext;
        private Guid _ViewModelId = Guid.NewGuid();
        protected Services.IPageConductor PageConductor { get; set; }

        public ViewModelBase()
            : base() {
            EntityManager.EntityChanged += OnEntityChanged;
            EntityManager.MessageCompleted += OnMessageCompleted;
        }

        public Object Model {
            get {
                return _Model;
            }
            set {
                if (_Model == value)
                    return;

                _Model = value;
                RaisePropertyChanged("Model");
            }
        }
        public NavigationService NavigationService {
            get { return _NavigationService; }
            set {
                if (_NavigationService == value)
                    return;
                _NavigationService = value;
                RaisePropertyChanged("NavigationService");
            }
        }
        public NavigationContext NavigationContext {
            get { return _NavigationContext; }
            set {
                if (_NavigationContext == value)
                    return;
                _NavigationContext = value;
                RaisePropertyChanged("NavigationContext");
            }
        }





        public EntityManager EntityManager {
            get {
                return EntityManager.Current;
            }
        }
        public Guid ViewModelId {
            get { return _ViewModelId; }
        }

        protected virtual void OnEntityChanged(Guid entityGuid, Type entityType, ChangeOperation changeOperation, Origin changeOrigin, IEntity entity) {
            return;
        }
        protected virtual void OnMessageCompleted(Message message) {
            return;
        }
    }
}
